package cn.com.gome;


import static com.sun.btrace.BTraceUtils.*;


import com.sun.btrace.AnyType;
import com.sun.btrace.annotations.*;

import java.lang.reflect.Field;

/**
 * Created by liuxianzhao on 2017/4/26.
 */
@BTrace
public class BtraceTest {


    //print System Properties:
    static {
        println("System Properties:");
        printProperties();
        println("VM Flags:");
        printVmArguments();
        println("OS Enviroment:");
        printEnv();
        exit(0);
    }

    @OnMethod(clazz = "com.alibaba.dubbo.rpc.protocol.dubbo.DubboInvoker", method = "doInvoke", location = @Location(Kind.RETURN))
    public static void traceDubboInvoker(@ProbeClassName String name, @ProbeMethodName String method ,
                                         @Self  Object  self , @Return AnyType result){
        Class AbstractInvoker = getSuperclass(classOf(self));
        Object url =get(field(AbstractInvoker, "url"), self);
        Object type =get(field(AbstractInvoker, "type"), self);
        println(type);
        Field hostField = field(classForName("com.alibaba.dubbo.common.URL",
                contextClassLoader()), "host");
        Object host = get(hostField,url);
        println(host);
        printFields(url);

        println("---------------------------------");
    }


}